package com.sumi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.enums.BusinessType;
import com.sumi.system.domain.FlwProcess;
import com.sumi.system.service.IFlwProcessService;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.common.core.page.TableDataInfo;

/**
 * 流程定义Controller
 * 
 * @author fgf67@163.com
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/system/process")
public class FlwProcessController extends BaseController
{
    @Autowired
    private IFlwProcessService flwProcessService;

    /**
     * 查询流程定义列表
     */
    @PreAuthorize("@ss.hasPermi('system:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlwProcess flwProcess)
    {
        startPage();
        List<FlwProcess> list = flwProcessService.selectFlwProcessList(flwProcess);
        return getDataTable(list);
    }

    /**
     * 导出流程定义列表
     */
    @PreAuthorize("@ss.hasPermi('system:process:export')")
    @Log(title = "流程定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlwProcess flwProcess)
    {
        List<FlwProcess> list = flwProcessService.selectFlwProcessList(flwProcess);
        ExcelUtil<FlwProcess> util = new ExcelUtil<FlwProcess>(FlwProcess.class);
        util.exportExcel(response, list, "流程定义数据");
    }

    /**
     * 获取流程定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(flwProcessService.selectFlwProcessById(id));
    }

    /**
     * 新增流程定义
     */
    @PreAuthorize("@ss.hasPermi('system:process:add')")
    @Log(title = "流程定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlwProcess flwProcess)
    {
        return toAjax(flwProcessService.insertFlwProcess(flwProcess));
    }

    /**
     * 修改流程定义
     */
    @PreAuthorize("@ss.hasPermi('system:process:edit')")
    @Log(title = "流程定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlwProcess flwProcess)
    {
        return toAjax(flwProcessService.updateFlwProcess(flwProcess));
    }

    /**
     * 删除流程定义
     */
    @PreAuthorize("@ss.hasPermi('system:process:remove')")
    @Log(title = "流程定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flwProcessService.deleteFlwProcessByIds(ids));
    }
}
